package com.yx.shop.service.admin.impl;

import com.yx.shop.dao.admin.AdminTypeDao;
import com.yx.shop.dao.admin.impl.AdminTypeDaoImpl;
import com.yx.shop.entitly.Type;
import com.yx.shop.service.admin.AdminTypeService;
import com.yx.shop.utils.JDBCUtils;

import java.util.List;

/**
 * @Classname AdminTypeServiceImpl
 * @Description TODO:
 * @Date 2021/05/10 17:38
 * @Created by yx
 */
public class AdminTypeServiceImpl implements AdminTypeService {
    private AdminTypeDao adminTypeDao = new AdminTypeDaoImpl();
    @Override
    public List<Type> getAllType() {
        List<Type> typeList = null;
        try {
            JDBCUtils.begin();
            List<Type> types = adminTypeDao.getAllType();
            if (types!=null){
                typeList=types;
            }
            JDBCUtils.commit();
        } catch (Exception e) {
            JDBCUtils.rollback();
            e.printStackTrace();
        }
        return typeList;
    }

    @Override
    public boolean insertType(Type type) {
        boolean flag = false;
        try {
            JDBCUtils.begin();
            if (adminTypeDao.insertType(type)>0) {
                flag=true;
            }
            JDBCUtils.commit();
        } catch (Exception e) {
            JDBCUtils.rollback();
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean deleteTypeByTid(Integer tid) {
        boolean flag = false;
        try {
            JDBCUtils.begin();
            if (adminTypeDao.deleteType(tid)>0) {
                flag=true;
            }
            JDBCUtils.commit();
        } catch (Exception e) {
            JDBCUtils.rollback();
            e.printStackTrace();
        }
        return flag;
    }
}
